<?php
/**
 *　                  oooooooooooo
 *
 *                  ooooooooooooooooo
 *                       o
 *                      o
 *                     o        o
 *                    oooooooooooo
 *
 *         ～～         ～～         　　～～
 *       ~~　　　　　~~　　　　　　　　~~
 * ~~～~~～~~　　　~~~～~~～~~～　　　~~~～~~～~~～
 * ·······              ~~XYHCMS~~            ·······
 * ·······  闲看庭前花开花落 漫随天外云卷云舒 ·······
 * ·············     www.xyhcms.com     ·············
 * ··················································
 * ··················································
 *
 * @Author: gosea <gosea199@gmail.com>
 * @Date:   2014-06-21 10:00:00
 * @Last Modified by:   gosea
 * @Last Modified time: 2016-06-21 12:39:28
 */

namespace Home\Controller;

class IndexController extends HomeCommonController
{
    //方法：index
    public function index()
    {

        go_mobile();
        $this->assign('title', C('CFG_WEBNAME'));
        $this->display();

    }

    public function saveVolunteer(){
        $data = I('post.');
        $data['addtime'] = time();
        $data['worktimestart'] = strtotime($data['worktimestart']);
        $data['worktimeend'] = strtotime($data['worktimeend']);
        $res = D("Volunteer")->data($data)->add();
        if($res){
            echo 'ok';
        }
    }

    public function applyJob(){
        $data['name'] = I('post.name');
        $data['phone'] = I('post.phone');
        $data['email'] = I('post.email');
        $data['interview_time'] = I('post.radio_group');
        $data['job_select'] = implode(I('post.check'),',');
        $data['resume'] = I('post.fileurl');
        $data['addtime'] = time();

        $res = D('JobApply')->data($data)->add();
        if($res){
            echo 'ok';
        }else{
            return false;
        }
    }

    public function getAmountInfo(){
        $amount = D("Donate")->field("sum(money) as totalmoney")->find();
        echo json_encode($amount);die;
    }

    public function getProjectlist(){
        $cid = I('cid');
        $list = D("Article")->where(array('cid'=>$cid))->select();
        $this->assign('list',$list);
        $content = $this->fetch('projectlist');
        echo $content;
    }

    /*public function upload(){
        if(count($_FILES) > 0)
        {
            $f = $_FILES['file'];
            $filename = 'Upload/' . md5(uniqid(rand())) . '_' . $f['name'];
            move_uploaded_file($f['tmp_name'], $filename);
            echo 'Success';
        }
        else
        {
            echo 'no files';
        }
    }*/
    public function upload($img_flag = 0)
    {
        header("Content-Type:text/html; charset=utf-8"); //不然返回中文乱码
        $result   = array('state' => '失败', 'url' => '', 'name' => '', 'original' => '');
        $sub_path = I('post.file', '', 'trim,htmlspecialchars'); //判断其他子目录

        $img_flag = empty($img_flag) ? 0 : 1;

        $yun_upload    = new \Common\Lib\YunUpload($img_flag, $sub_path);
        $upload_result = $yun_upload->upload();
        if ($upload_result['status']) {
            $result['state'] = 1;
            $result['info']  = $upload_result['info'];
            $result['url'] = $upload_result['data'][0]['url'];
            $result['name'] = $upload_result['data'][0]['name'];
        } else {
            $result['state'] = 0;
            $result['info'] = $upload_result['info'];
        }
        echo json_encode($result);

    }
}
